import React from 'react';
import ReactDOM from 'react-dom';
import './style.scss';
import Home from './app/home/home';
import registerServiceWorker from './registerServiceWorker';
import {
    BrowserRouter as Router,
    Route
  } from 'react-router-dom';
import routes from './routings';

const RouteWithSubRoutes = (route) => (
  <Route path={route.path} render={props => (
    // pass the sub-routes down to keep nesting
    <route.component {...props} routes={route.routes}/>
  )}/>
)

console.log(process.env);

/**
 * 初始化页面
 */
const init = () => {
  const RouteConfigExample = () => {
      return (
      <Router>
          <div>
          <Route exact path="/" component={Home}/>
          {routes.map((route, i) => (
              <RouteWithSubRoutes key={i} {...route}/>
          ))}
          </div>
      </Router>
  )}

  ReactDOM.render(<RouteConfigExample />, document.getElementById('root'));
}

init();
registerServiceWorker();
